package com.lx.mobileplayer.mvp.view.activity

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.lx.mobileplayer.R
import com.lx.mobileplayer.mvp.view.Iview.IBaseView
import com.lx.mobileplayer.utils.AppManager

/**
 * 类说明：所有activity的基类
 * Created by liuxiong on 2019/4/22.
 */
abstract class BaseActivity : AppCompatActivity() ,IBaseView{

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getContentLayoutId())

        //加入到管理
        AppManager.addActivity(this)
        
        initView()
        
        initData()
    }


    /**
    * 方法说明:  获取内容布局Id
    * @return
    * created by liuxiong on 14:24
    */
    abstract fun getContentLayoutId(): Int
    
    
    /**
    * 方法说明:  初始化控件
    * created by liuxiong on 2019/4/24 14:13
    */
    open fun initView(){}

    /**
    * 方法说明:  初始化数据
    * created by liuxiong on 2019/4/24 14:15
    */
    open fun initData(){}

    override fun getMContext(): Activity {
        return this
    }

    override fun getAppContext(): Context {
        return  this.applicationContext
    }

    override fun finish() {
        super.finish()

        //移除管理
        AppManager.removeActivity(this)

        //统一的动画效果
        if(this is MainActivity){  //退出应用不加动画
            return
        }
        //页面退出动画
        overridePendingTransition(R.anim.anim_activity_finish_in, R.anim.anim_activity_finish_out)

    }

}